package com.ruoyi.task.service.impl;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.task.domain.Task;
import com.ruoyi.task.domain.TaskReport;
import com.ruoyi.task.mapper.TaskReportMapper;
import com.ruoyi.task.service.ITaskReportService;
import com.ruoyi.task.service.ITaskService;
import com.ruoyi.wechat.service.IWechatUserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 任务举报Service业务层处理
 *
 * @author KevenPotter
 * @date 2024-05-02 18:55:06
 */
@Service
@AllArgsConstructor
public class TaskReportServiceImpl implements ITaskReportService {

    private final ITaskService taskService;
    private final IWechatUserService wechatUserService;
    private final TaskReportMapper taskReportMapper;

    /**
     * 查询任务举报
     *
     * @param id 任务举报主键
     * @return 任务举报
     */
    @Override
    public TaskReport getById(Long id) {
        return taskReportMapper.getById(id);
    }

    /**
     * 查询任务举报列表
     *
     * @param taskReport 任务举报
     * @return 任务举报
     */
    @Override
    public List<TaskReport> getList(TaskReport taskReport) {
        return taskReportMapper.getList(taskReport);
    }

    /**
     * 新增任务举报
     *
     * @param taskReport 任务举报
     * @return 结果
     */
    @Override
    public int insertTaskReport(TaskReport taskReport) {
        taskReport.setCreateTime(DateUtils.getNowDate());
        return taskReportMapper.insertTaskReport(taskReport);
    }

    /**
     * 修改任务举报
     *
     * @param taskReport 任务举报
     * @return 结果
     */
    @Override
    public int updateTaskReport(TaskReport taskReport) {
        return taskReportMapper.updateTaskReport(taskReport);
    }

    /**
     * 批量删除任务举报
     *
     * @param ids 需要删除的任务举报主键
     * @return 结果
     */
    @Override
    public int deleteTaskReportByIds(Long[] ids) {
        return taskReportMapper.deleteTaskReportByIds(ids);
    }

    /**
     * 删除任务举报信息
     *
     * @param id 任务举报主键
     * @return 结果
     */
    @Override
    public int deleteTaskReportById(Long id) {
        return taskReportMapper.deleteTaskReportById(id);
    }

    /**
     * 过滤出埠参数参数
     *
     * @param taskReport 任务举报对象
     * @param loginUser  当前登录对象
     * @return 返回过滤后的[任务举报对象]
     * @author KevenPotter
     * @date 2024-05-02 19:08:24
     */
    @Override
    public TaskReport filterInbound(TaskReport taskReport, LoginUser loginUser) {
        if (taskReport.getTaskId() != null) {
            Task task = taskService.getById(taskReport.getTaskId());
            taskReport.setTaskTitle(task.getTitle()).setItem(task.getItem());
        }
        return taskReport;
    }

    /**
     * 过滤出埠参数参数
     *
     * @param taskReport 任务举报对象
     * @param loginUser  当前登录对象
     * @return 返回过滤后的[任务举报对象]
     * @author KevenPotter
     * @date 2024-05-02 19:08:39
     */
    @Override
    public TaskReport filterOutbound(TaskReport taskReport, LoginUser loginUser) {
        if (taskReport.getReportUserId() != null) taskReport.setReportUserName(wechatUserService.getById(taskReport.getReportUserId()).getNickName());
        return taskReport;
    }
}
